<?php

//Selectionne un ou plusieurs commentaires 
function selectComments($bdd, $valeur) {
    //Si on est sur la page d'une oeuvre
    if ($valeur == "work") {
        if (isset($_GET['details'])) {
            $where = 'WHERE id_work = ' . $_GET['details'];
        } else if (isset($_POST['id_work'])) {
            $where = 'WHERE id_work = ' . $_POST['id_work'];
        }
    }


    $req = $bdd->query('SELECT * FROM comments ' . $where . ' ORDER BY date_hour ');
    return $req;
}

//Selectionne un commentaire
function selectOneComment($bdd, $id) {
    $req = $bdd->query('SELECT * FROM comments WHERE id_comment=' . $id);
    return $req;
}

//Creer un nouveau commentaire pour une oeuvre
function modelcreatecomment($bdd) {
    $req = $bdd->query('INSERT INTO comments (id_comment, id_work, text, date_hour, comment_pseudo, comment_email) 
							VALUES(NULL, ' . $_GET['details'] . ', \'' . $_POST['text'] . '\', now(), \'' . $_POST['pseudo'] . '\', \'' . $_POST['email'] . '\')');
}

?>